<template>
  <el-container>
    <el-header>
      <div class="login-box">
        <img src="../assets/img/heima.png" alt />
        <span>电商后台管理系统</span>
        <el-button type="info" @click='logout()'>退出</el-button>
      </div>
    </el-header>
    <el-container>
      <el-aside :width="menushow?'65px':'200px'">
        <div id="toogle_bar" @click="menushow=!menushow">|||</div>
        <el-menu
          background-color="#333744"
          text-color="#fff"
          active-text-color="blue"
          unique-opened
          :collapse="menushow"
          :collapse-transition="false"
        >
          <el-submenu
            v-for=" item in menuList"
            :key="item.id"
            :index="item.id+''"
            :style="{width:menushow?'65px':'200px'}"
          >
            <template slot="title">
              <i :class="'iconfont icon-'+icons['ic'+item.id]"></i>
              <span>{{item.authName}}</span>
            </template>
            <el-menu-item-group>
              <el-menu-item :index="item2.id+''" v-for="item2 in item.children" :key="item2.id">
                <template slot="title">
                  <i class="el-icon-menu"></i>
                  <span>{{item2.authName}}</span>
                </template>
              </el-menu-item>
            </el-menu-item-group>
          </el-submenu>
        </el-menu>
      </el-aside>
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  created () {
    this.getMenuList()
  },
  data () {
    return {
      menushow: false, // 控制左侧菜单折叠
      menuList: [], // 储存左侧导航菜单数据
      // 给左侧菜单设置图标
      icons: {
        ic125: 'users',
        ic103: 'tijikongjian',
        ic101: 'shangpin',
        ic102: 'danju',
        ic145: 'baobiao'
      }
    }
  },
  methods: {
    async getMenuList () {
      var { data: dt } = await this.$http.get('/menus')
      // if (dt.mata.status !== 200) {
      //   return this.$message.error(dt.metamsg)
      // }
      console.log(dt)

      this.menuList = dt.data
    },
    logout () {
      this.$confirm('此操作将永久删除该文件, 是否继续?', '退出', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        window.sessionStorage.removeItem('token')
        this.$router.push('/login')
      }).catch(() => {

      })
    }
  }
}
</script>

<style lang="less" scoped>
// .el-submenu__title span{
//   font-size: 13px;
// }
.el-container {
  height: 100%;
  .el-aside {
    background-color: #333744;
  }
  .el-header {
    background-color: #373d41;
    padding: 0;
    display: flex;
    align-items: center;
    .login-box {
      color: #fff;
      display: flex;
      align-items: center;
      font-size: 22px;
      user-select: none;
      span {
        margin-left: 10px;
      }
      img {
        width: 50px;
      }
    }
    .el-button {
      position: absolute;
      right: 20px;
    }
  }
  .el-main {
    background-color: #eaedf1;
  }
}
.el-aside {
  #toogle_bar {
    color: #fff;
    text-align: center;
    background-color: #4a5064;
    height: 25px;
    line-height: 25px;
    letter-spacing: 0.1em;
    cursor: pointer;
    user-select: none;
  }
}
</style>
